package cn.dlc.com.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import cn.dlc.com.property.ZookeeperProperty;
import cn.dlc.com.server.XietiaoServer;

@Configuration
@EnableConfigurationProperties(ZookeeperProperty.class)
public class AppConfig {
	
	@Autowired
	private Environment env;

	@Bean
	public XietiaoServer serverConfig(ZookeeperProperty zk) {
		XietiaoServer serverConfig = new XietiaoServer(zk.getUrl(), zk.getNodePath());
		// 通过传递过来的参数设置临时节点，
		serverConfig.registServer(zk.getNodePath(), env.getProperty("serverName"), env.getProperty("content"));
		return serverConfig;
	}
}
